import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
channel = connection.channel()

channel.exchange_declare(exchange='logs5',  # 交换机名称
                         exchange_type='topic')  # 模式---通配符

message = 'info.news: Hello World'
channel.basic_publish(exchange='logs5',  # 指定交换机
                      routing_key='info.news',  # 关键字
                      body=message)

message2 = 'info.news.xxx: Hello World'
channel.basic_publish(exchange='logs5',  # 指定交换机
                      routing_key='info.news.xxx',  # 关键字
                      body=message2)

print(" [x] Sent %r" % message)
connection.close()


